const { connect } = dva;
const { Form, Input, Button } = antd;
const { Item } = Form;
const { CrudForm } = require('../../Widgets.jsx');
const Constants = require("../../Constants.jsx");
import { namespace } from '../../../models/sys/Module.jsx'

class SysModuleForm extends CrudForm {
    static defaultProps = {
        namespace: namespace
    };
    render() {
        const { form: { getFieldDecorator }, edit: { record }, loading } = this.props, { item: { layout, tailLayout }} = Constants.FORM;
        return (
            <div style={{padding: '40px 20px'}}>
                <Form onSubmit={this.handleSubmit.bind(this)}>
                    <Item
                        {...layout}
                        label={<span className="form-title">系统模块{record ? '修改' : '录入'}</span>}
                        colon={false}
                    >
                    </Item>
                    <Item
                        {...layout}
                        label="模块名称"
                        hasFeedback
                    >
                        {getFieldDecorator('name', {
                            rules: [{
                                required: true, message: '请输入模块名称!',
                            }],
                        })(
                            <Input/>
                        )}
                    </Item>
                    <Item {...tailLayout}>
                        <Button type="primary" htmlType="submit" disabled={loading} size="large">提交</Button>
                    </Item>
                </Form>
            </div>
        );
    }
}

module.exports = connect(state => {
    return { ...state[namespace], loading: state.loading.models[namespace]  }
})(Form.create()(SysModuleForm));